package com.java110.mall.goods.cmd.product;

import com.alibaba.fastjson.JSONObject;
import com.java110.core.annotation.Java110Cmd;
import com.java110.core.annotation.Java110Transactional;
import com.java110.core.context.Environment;
import com.java110.core.context.ICmdDataFlowContext;
import com.java110.core.event.cmd.Cmd;
import com.java110.core.event.cmd.CmdEvent;
import com.java110.intf.goods.IProductInnerServiceSMO;
import com.java110.po.product.ProductPo;
import com.java110.utils.exception.CmdException;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import com.java110.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;

@Java110Cmd(serviceCode = "product.deleteProduct")
public class DeleteProductCmd extends Cmd {

    @Autowired
    private IProductInnerServiceSMO productInnerServiceSMOImpl;
    @Override
    public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {
        Environment.isDevEnv();
        Assert.hasKeyAndValue(reqJson, "shopId", "商铺不能为空");
        Assert.hasKeyAndValue(reqJson, "productId", "productId不能为空");
    }

    @Override
    @Java110Transactional
    public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {

        ProductPo productPo = BeanConvertUtil.covertBean(reqJson, ProductPo.class);

        int flag = productInnerServiceSMOImpl.deleteProduct(productPo);

        if (flag <1) {
            throw new CmdException("删除失败");
        }

    }
}
